package com.rmy.queue.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.rmy.queue.domain.QmsBusinessConfig;
import com.rmy.queue.service.IQmsBusinessConfigService;
import com.rmy.queue.service.IQmsWindowBusinessService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rmy.common.annotation.Log;
import com.rmy.common.core.controller.BaseController;
import com.rmy.common.core.domain.AjaxResult;
import com.rmy.common.enums.BusinessType;
import com.rmy.queue.domain.QmsErpRule;
import com.rmy.queue.service.IQmsErpRuleService;
import com.rmy.common.utils.poi.ExcelUtil;
import com.rmy.common.core.page.TableDataInfo;

/**
 * 队列规则Controller
 * 
 * @author rmy
 * @date 2022-09-30
 */
@RestController
@RequestMapping("/queue/erprule")
public class QmsErpRuleController extends BaseController
{
    @Autowired
    private IQmsErpRuleService qmsErpRuleService;

    @Autowired
    private IQmsBusinessConfigService qmsBusinessConfigService;

    /**
     * 查询队列规则列表
     */
    @PreAuthorize("@ss.hasPermi('queue:erprule:list')")
    @GetMapping("/list")
    public TableDataInfo list(QmsErpRule qmsErpRule)
    {
        startPage();
        List<QmsErpRule> list = qmsErpRuleService.selectQmsErpRuleList(qmsErpRule);
        return getDataTable(list);
    }

    /**
     * 导出队列规则列表
     */
    @PreAuthorize("@ss.hasPermi('queue:erprule:export')")
    @Log(title = "队列规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QmsErpRule qmsErpRule)
    {
        List<QmsErpRule> list = qmsErpRuleService.selectQmsErpRuleList(qmsErpRule);
        ExcelUtil<QmsErpRule> util = new ExcelUtil<QmsErpRule>(QmsErpRule.class);
        util.exportExcel(response, list, "队列规则数据");
    }

    /**
     * 获取队列规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('queue:erprule:query')")
    @GetMapping(value = "/{businessId}")
    public AjaxResult getInfo(@PathVariable("businessId") Long businessId)
    {
        return AjaxResult.success(qmsErpRuleService.selectQmsErpRuleByBusinessId(businessId));
    }

    /**
     * 新增队列规则
     */
    @PreAuthorize("@ss.hasPermi('queue:erprule:add')")
    @Log(title = "队列规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QmsErpRule qmsErpRule)
    {
        return toAjax(qmsErpRuleService.insertQmsErpRule(qmsErpRule));
    }

    /**
     * 修改队列规则
     */
    @PreAuthorize("@ss.hasPermi('queue:erprule:edit')")
    @Log(title = "队列规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QmsErpRule qmsErpRule)
    {
        return toAjax(qmsErpRuleService.updateQmsErpRule(qmsErpRule));
    }

    /**
     * 删除队列规则
     */
    @PreAuthorize("@ss.hasPermi('queue:erprule:remove')")
    @Log(title = "队列规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{businessIds}")
    public AjaxResult remove(@PathVariable Long[] businessIds)
    {
        return toAjax(qmsErpRuleService.deleteQmsErpRuleByBusinessIds(businessIds));
    }




    /**
     * 查询业务数据配置字典
     */
    @GetMapping(value = "/getBusinessDict/{exceptBind}")
    public AjaxResult getBusinessDict(@PathVariable boolean exceptBind)
    {
        return AjaxResult.success(qmsBusinessConfigService.selectBusinessDataType(exceptBind));
    }
}
